//
//  NetworkServiceManager.h
//  laziz_Consumer
//
//  Created by XMac on 16/11/9.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "AFNetworking.h"

/**
 下载完成block

 @param response 响应对象
 @param filePath 文件下载后的地址
 @param error 错误对象
 */
typedef void(^DownloadCompletionHandler)(NSURLResponse *response, NSURL *filePath, NSError *error);

/**
 上传完成block

 @param response 响应对象
 @param responseObject 返回数据
 @param error 错误对象
 */
typedef void(^UploadCompletionHandler)(NSURLResponse *response, id responseObject, NSError *error);

/**
 进度block
 */
typedef void(^ProgressHandler)(NSProgress *downloadProgress);

@interface NetworkServiceManager : NSObject


+(instancetype)manager;

/**
 下载文件
 
 @param urlStr 下载地址
 @param progressHandler 进度block
 @param completionHandler 下载完成block
 @return task对象
 */
-(NSURLSessionDownloadTask *)executeDownloadTask:(NSString *)urlStr progress:(ProgressHandler)progressHandler completion:(DownloadCompletionHandler)completionHandler;

/**
 上传文件
 
 @param urlStr 上传地址
 @param xfilePath 上传文件地址
 @param progressHandler 进度block
 @param completionHandler 上传完成block
 @return task对象
 */
-(NSURLSessionUploadTask *)executeUploadTask:(NSString *)urlStr filePath:(NSString *)xfilePath progress:(ProgressHandler)progressHandler completion:(UploadCompletionHandler)completionHandler;




/**
 get请求的便利方法
 */
-(NSURLSessionDataTask *)executGetTask:(NSString *)urlStr parameters:(id)parameter success:(void (^)(NSURLSessionDataTask *task , id resultData))success fail:(void (^)(NSURLSessionDataTask *task , NSError *error))failure;


/**
 get请求
 
 @param urlStr 请求地址
 @param parameter 参数
 @param progressHandler 进度
 @param success 成功block
 @param failure 失败block
 @return task对象
 */
-(NSURLSessionDataTask *)executGetTask:(NSString *)urlStr parameters:(id)parameter progress:(ProgressHandler)progressHandler success:(void (^)(NSURLSessionDataTask *task , id resultData))success fail:(void (^)(NSURLSessionDataTask *task , NSError *error))failure;




/**
 post请求便利方法
 */
-(NSURLSessionDataTask *)executePostTask:(NSString *)urlStr parameters:(id)parameter success:(void (^)(NSURLSessionDataTask *task, id resultData))success fail:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;


/**
 post请求
 
 @param urlStr 请求地址
 @param parameter 参数
 @param progressHandler 进度
 @param success 成功block
 @param failure 失败block
 @return task对象
 */

-(NSURLSessionDataTask *)executePostTask:(NSString *)urlStr parameters:(id)parameter progress:(ProgressHandler)progressHandler success:(void (^)(NSURLSessionDataTask *task , id resultData))success fail:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 post请求
 
 @param urlStr 请求地址
 @param parameter 参数
 @param block 请求头构造block
 @param progressHandler 进度
 @param success 成功block
 @param failure 失败block
 @return task对象
 */

-(NSURLSessionDataTask *)executePostTask:(NSString *)urlStr parameters:(id)parameter constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block progress:(ProgressHandler)progressHandler success:(void (^)(NSURLSessionDataTask *task , id resultData))success fail:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;



@end
